const db = uniCloud.database()
const userCollectionName = 'uni-id-users'
const userCollection = db.collection(userCollectionName)
const verifyCollectionName = 'opendb-verify-codes'
const verifyCollection = db.collection(verifyCollectionName)
const roleCollectionName = 'uni-id-roles'
const roleCollection = db.collection(roleCollectionName)
const permissionCollectionName = 'uni-id-permissions'
const permissionCollection = db.collection(permissionCollectionName)

// 单端用户唯一字段，注意有些字段是对象类型
const uniqueUserParam = {
  username: '用户名',
  mobile: '手机号',
  email: '邮箱',
  wx_unionid: '微信账号',
  'wx_openid.app-plus': '微信账号',
  'wx_openid.mp-weixin': '微信账号',
  qq_unionid: 'QQ账号',
  'qq_openid.app-plus': 'QQ账号',
  'qq_openid.mp-weixin': 'QQ账号',
  ali_openid: '支付宝账号',
  apple_openid: '苹果账号'
}

// 公用错误码
const PublicErrorCode = {
  DB_ERROR: 90001,
  PARAM_REQUIRED: 90002,
  PARAM_ERROR: 90003,
  USER_NOT_EXIST: 90004,
  ROLE_NOT_EXIST: 90005,
  PERMISSION_NOT_EXIST: 90006
}

export {
  db,
  PublicErrorCode,
  userCollection,
  verifyCollection,
  roleCollection,
  permissionCollection,
  userCollectionName,
  verifyCollectionName,
  roleCollectionName,
  permissionCollectionName,
  uniqueUserParam
}
